// 1. 字符串slice是String中一部分值的引用
// 2. 字面值就是slice
// 3. 其他类型slice
fn main() {
    let s = String::from("hello world");
    // 也叫切片
    let h = &s[0..5];
    println!("h = {h}");
    let h1 = &s[..5];
    println!("h1 = {h1}");
    let h2 = &s[..=4];
    println!("h2 = {h2}");

    let w = &s[6..11];
    println!("w = {w}");
    let w1 = &s[6..];
    println!("w1 = {w1}");
    let w2 = &s[6..=10];
    println!("w2 = {w2}");

    // String的切片
    let s = String::from("中文");
    // UTF-8一个中文3个字符
    let zh = &s[..3];
    println!("zh = {zh}");

    // 数组切片
    let a = [1,2,3,4,5];
    let b = &a[1..3];
    println!("b = {}", b[0]);
    println!("b = {}", b[1]);
    println!("b len = {}", b.len());
    println!("Hello, world!");
}
